home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection 1998 Fall: Game Toolkit / Disc.iso / Samples / Moofwars 1.02 / MoofWars Sprocket / •Headers / TTileGrid.h < prev   
Encoding:
C/C++ Source or Header  |  1997-11-05  |  3.6 KB  |  116 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************
  2. TTileGrid.h
  3.  
  4. A TileGrid is a class that describes a 2 dimensional array of tiles that can be
  5. drawn as the background for a game.  This current version only supplies
  6. graphics routines, but collision and other logic should be fairly easy to
  7. generate.
  8.  
  9. Author: Timothy Carroll
  10. Apple Developer Technical Support
  11. timc@apple.com
  12.  
  13. Modification History: 
  14.  
  15. 8/15/96        TMC     Initial Release
  16.  
  17. Copyright © 1996 Apple Computer, Inc., All Rights Reserved
  18.  
  19. You may incorporate this sample code into your applications without
  20. restriction, though the sample code has been provided "AS IS" and the
  21. responsibility for its operation is 100% yours.  However, what you are
  22. not permitted to do is to redistribute the source as "DSC Sample Code"
  23. after having made changes. If you're going to re-distribute the source,
  24. we require that you make it clear in the source that the code was
  25. descended from Apple Sample Code, but that you've made changes.
  26. *************************************************************************************/
  27.  
  28. #ifndef _TTILEGRID_
  29. #define _TTILEGRID_
  30.  
  31. #pragma once
  32.  
  33. #include "TTileCollection.h"
  34. #include "GridTilesFormat.h"
  35.  
  36.  
  37. #if PRAGMA_STRUCT_ALIGN
  38. #pragma options align=power
  39. #endif
  40.  
  41.  
  42.  
  43.  
  44. class TTileGrid {
  45.  
  46.     public:
  47.     
  48.     /*************************************************************************************
  49.     Constructor/Destructor
  50.     
  51.     Constructor is mostly used to initialize the object to a clean and known state, but
  52.     doesn't do any actual work.  The actual work of creating the object is a later call.
  53.     
  54.     The Destructor frees all allocated memory and releases the link to the Tile Collection.
  55.     
  56.     *************************************************************************************/
  57.  
  58.     TTileGrid (void);
  59.     ~TTileGrid (void);
  60.  
  61. /*************************************************************************************
  62.     Creating a TileGrid.
  63.     
  64.     A TileGrid (by default) is loaded from a resource, although the potential exists to
  65.     create other methods of creating the tile grid.
  66.  
  67. *************************************************************************************/
  68.     OSErr CreateGridFromResource (SInt16 resID);
  69.     
  70.     
  71. /*************************************************************************************
  72.     Accessors
  73.     
  74.     A couple of accessors are provided for looking up the grid values.  By default, if
  75.     the h and v are outside the grid bounds, we return the "defaultTile" value.
  76.  
  77. *************************************************************************************/
  78.     
  79.     CellGridType GetGridValue (SInt32 h, SInt32 v);
  80.     void SetGridValue (SInt32 h, SInt32 v, CellGridType value);
  81.     
  82.     SInt32    GetGridWidth (void) { return fWidth;};
  83.     SInt32  GetGridHeight (void) { return fHeight;};
  84.     
  85. /*************************************************************************************
  86.     Drawing
  87.     
  88.     This routine takes a point in 16.16 global space, and the clipping rectangle in screen
  89.     coordinates, and does all the right things to draw the grid inside the entire clip rect.
  90.  
  91. *************************************************************************************/
  92.     
  93.     void   DrawGrid (Rect *screenRect, SInt32 topGlobal, SInt32 leftGlobal);
  94.  
  95.  
  96. /*************************************************************************************
  97.     Data for a TileGrid object.
  98.     
  99. *************************************************************************************/
  100.     
  101.     protected:
  102.     
  103.     SInt32                fWidth;
  104.     SInt32                fHeight;
  105.     UInt32                fDefaultTile; // used to draw all out of bounds tiles.
  106.     TTileCollection     *fTiles;
  107.     CellGridType        **fTileData; // variable length array of cell data.
  108. };
  109.  
  110. #if PRAGMA_STRUCT_ALIGN
  111. #pragma options align=reset
  112. #endif
  113.  
  114.  
  115. #endif /* _TTILEGRID_ */
  116.